pdf generation with php - getting started

chris (2002-12-18 17:57:03)
4004 views
1 replies
I had a bit of a bum time today getting php on a friend's box to swallow pdflib. I think the main issue was that I was using pdflib-3.03 - force of habit having installed the PERL equivqlents on a handful of boxen.
So after too many attempts with too many versions and a sprinkling of dependencies, I'll summarise with:

dependencies:
zlib
libpng
tifflib
libjpg
pdflib

The installation of zlib, libpng, tifflib is pretty standard under linux

Now working with pdflib-4.0.3, run the ususal ./configure && make && make test && make install && cd.. and you're ready to take on the php build.

# cd php-4.2.2
# make clean

and here is the config options list:

# ./configure \
--with-mysql \
--with-apxs=/usr/local/apache/bin/apxs \
--enable-track-vars \
--enable-exif \
--with-gd=../gd-1.8.3 \
--with-jpeg-dir=../jpeg-6b/ \
--with-png-dir=../libpng-1.2.4 \
--with-zlib-dir=../zlib-1.1.4 \
--with-pdflib=/usr/local/ \
--with-tiff-dir=/usr/local/

# make && make install to finish off and lo and behold you have php with pdf support. Try this sample script - just paste it into your editor, and load it in a browser.. make sure your system knows where to find its pdf reader (adobe acrobat or xpdf are the norm):

<?php

/*
the standard test script for php & pdflib
*/

$p = pdf_new();
pdf_open_file($p);
pdf_set_info($p,"Creator","hello.php");
pdf_set_info($p,"Author","foo bar");
pdf_set_info($p,"Title","Hello world (PHP)");
pdf_begin_page($p,595,842);
$font = pdf_findfont($p,"Helvetica-Bold","host",0);
pdf_setfont($p,$font,38.0);
pdf_show_xy($p,"Hello world!",50,700);
pdf_end_page($p);
pdf_close($p);
$buf = pdf_get_buffer($p);
$len = strlen($buf);
Header("Content-type: application/pdf");
Header("Content-Length: $len");
Header("Content-Disposition: inline; filename=hello_php.pdf");
echo $buf;
pdf_delete($p);
?>

have fun,

christo
comment
chris
2002-12-20 09:50:00

libtoff download

Just a footnote - I should point out that libtiff can be downloaded from ftp://ftp.remotesensing.org/pub/libtiff

christo
reply icon